#!/usr/bin/env

#configure for user
OBSSERVER_IP="100.109.85.100"
set +u
if [ "x${obs_server_from_jenkins}" != "x" ]; then
    OBSSERVER_IP="${obs_server_from_jenkins}"
fi
set -u
OBSPASSWD="EulerOS_123"
ISCI=1
MYVERSION="EulerOS_V200R008C00"
IP="10.120.107.75"
USER="root"
PASSWD="EulerOS_123"
ICP_CI_IP="10.116.245.114"
PROJECT_PATH=$(cd `dirname $0`;pwd)

ISO_NAME="EulerOS"
ISO_VERSION="V3.0SP5"
ARCH="x86_64"
export DVD_NAME="${ISO_NAME}-${ISO_VERSION}-${ARCH}-dvd.iso"
export SOURCE_NAME="${ISO_NAME}-${ISO_VERSION}-source-dvd.iso"
export SHA256SUM=".sha256sum"

gcov_obs_projects="GCOV_EulerOS_T:V3R1:BuildToolsBep GCOV_EulerOS_T:V3R1:COMMOM GCOV_EulerOS_T:V3R1:CompileTools GCOV_EulerOS_T:V3R1:GENERAL GCOV_EulerOS_T:V3R1:KIWI GCOV_EulerOS_T:V3R1:PANGEA GCOV_EulerOS_T:V3R1:STANDARD GCOV_EulerOS_T:V3R1:UVP"

if echo "$PROJECT_PATH" | grep '_gcov'; then
    export CI_PROJECT="EulerOS_V200R008C00_X86_gcov"
elif [ -f /.dockerenv -a -f /root/version ];then
    if cat /root/version | grep '_gcov'; then
        export CI_PROJECT="EulerOS_V200R008C00_X86_gcov"
    else
        export CI_PROJECT="EulerOS_V200R008C00_X86"
    fi
else
    export CI_PROJECT="EulerOS_V200R008C00_X86"
fi

export WORK_DIR="/usr1/ci_workdir/$CI_PROJECT/"
export SUB_RELEASE_DIR="Software/x86_64"
export CMC_BASEDIR="/usr1"

obs_kernel_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64/x86_64/"
obs_kernel_noarch_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64/noarch/"
obs_common_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/COMMOM/standard_x86_64/"
obs_standard_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/STANDARD/standard_x86_64/"
obs_general_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL/standard_x86_64/"
obs_custom_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Custom/standard_x86_64/"
obs_docker_url="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/STANDARD:/Docker/standard_x86_64/"

export OBS_PROJECTS="http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/COMMOM/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/COMMOM/standard_i686 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/STANDARD/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Custom/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Custom/standard_i686 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/KIWI/standard_x86_64 http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/STANDARD:/Docker/standard_x86_64/ http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/CompileTools/standard_x86_64/ http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/STANDARD:/LibStorage/standard_x86_64/"

#for make_livecd
livecd_repo="custom_i686#../../EulerOS:/V3R1:/GENERAL:/Custom/standard_i686/i686/ custom_noarch#../../EulerOS:/V3R1:/GENERAL:/Custom/standard_x86_64/noarch/ custom_x86_64#../../EulerOS:/V3R1:/GENERAL:/Custom/standard_x86_64/x86_64/ custom_src#../../EulerOS:/V3R1:/GENERAL:/Custom/standard_x86_64/src/ kernel_noarch#../../EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64/noarch/ kernel_x86_64#../../EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64/x86_64/ kernel_src#../../EulerOS:/V3R1:/GENERAL:/Kernel/standard_x86_64/src/ common_i686#../../EulerOS:/V3R1:/COMMOM/standard_i686/i686/ common_noarch#../../EulerOS:/V3R1:/COMMOM/standard_x86_64/noarch/ common_x86_64#../../EulerOS:/V3R1:/COMMOM/standard_x86_64/x86_64/ common_src#../../EulerOS:/V3R1:/COMMOM/standard_x86_64/src/ standard_i686#../../EulerOS:/V3R1:/STANDARD/standard_i686/i686/ standard_noarch#../../EulerOS:/V3R1:/STANDARD/standard_x86_64/noarch/ standard_x86_64#../../EulerOS:/V3R1:/STANDARD/standard_x86_64/x86_64/ standard_src#../../EulerOS:/V3R1:/STANDARD/standard_x86_64/src/ general_noarch#../../EulerOS:/V3R1:/GENERAL/standard_x86_64/noarch/ general_x86_64#../../EulerOS:/V3R1:/GENERAL/standard_x86_64/x86_64/ general_i686#../../EulerOS:/V3R1:/GENERAL/standard_i686/i686/ general_src#../../EulerOS:/V3R1:/GENERAL/standard_x86_64/src/ docker_noarch#../../EulerOS:/V3R1:/STANDARD:/Docker/standard_x86_64/noarch/ docker_x86_64#../../EulerOS:/V3R1:/STANDARD:/Docker/standard_x86_64/x86_64/ docker_src#../../EulerOS:/V3R1:/STANDARD:/Docker/standard_x86_64/src/ tools_x86_64#../../EulerOS:/V3R1:/CompileTools/standard_x86_64/x86_64/ tools_noarch#../../EulerOS:/V3R1:/CompileTools/standard_x86_64/noarch/ tools_src#../../EulerOS:/V3R1:/CompileTools/standard_x86_64/src/ tools_i686#../../EulerOS:/V3R1:/CompileTools/standard_i686/i686/"

gerrit_branch="next"
gerrit_base_url="http://prtosci:SqENmC-3@dgggit09-rd.huawei.com/a"

function sshcmd()
{
    sh "$TOOLS"/safe_sshcmd.sh -c "$1" -m "$IP" -u "$USER" -p "$PASSWD" -t 120 -n 3
}

function sshscp()
{
    sh "$TOOLS"/safe_sshscp.sh -p "$PASSWD" -s "$1" -d "$IP:$2" -r -t 120 -n 3
}

function sshscp_from()
{
    sh "$TOOLS"/safe_sshscp.sh -p "$PASSWD" -s "$IP:$1" -d "$2" -r -t 120 -n 3
}

function modify_for_gcov()
{
    root_path=$1
    for prj in `echo $GCOV_OBS_PROJECTS`
    do
        prj=$(echo "${prj}" | sed 's/EulerOS_T/EulerOS/g')
        old_prj=$(echo "${prj}" | sed 's/GCOV_EulerOS/EulerOS/g')
        old_repo=$(echo "${old_prj}" | sed 's/:/:\//g')
        repo=$(echo "${prj}" | sed 's/:/:\//g')
        files=$(find "${root_path}" -type f | grep  -v "gcov_.*repo" | xargs egrep "$old_prj" | awk -F':' '{print $1}' | sort | uniq)
        if [ -n "${files}" ]; then
            sed -i "s#$old_prj#$prj#g" ${files}
        fi
        files=$(find "${root_path}" -type f | grep  -v "gcov_.*repo" | xargs egrep "${old_repo}" | awk -F':' '{print $1}' | sort | uniq)
        if [ -n "${files}" ]; then
            sed -i "s#$old_repo#$repo#g" ${files}
        fi
    done
    grep "GCOV_GCOV_" "${root_path}" -lR | grep -v config.sh | while read line
    do
        sed -i 's#GCOV_GCOV_#GCOV_#g' ${line}
    done
}
